<?php
namespace AdminApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RenewedordersApiController extends AbstractRestfulController
{
    public function getList()
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$renewedOrders = $userMedicineOrderTable->getAllRenewedOrders()->toArray();
		if(count($renewedOrders)!=0){
			return new JsonModel(array(
				'value'			=>	1,
				'result'		=>  $renewedOrders,
			));
		}else{
			return new JsonModel(array(
				'value'			=>	0,
				'renewedOrders'		=> 	'Orders list is empty',
			));
		}
    }
    public function get($id)
    {	
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$renewedOrders = $userMedicineOrderTable->getTommorowRenewedOrders()->toArray();
		if(count($renewedOrders)!=0){
			return new JsonModel(array(
				'value'			=>	1,
				'result'		=> $renewedOrders,
			));
		}else{
			return new JsonModel(array(
				'value'			=>	0,
				'renewedOrders'		=> 	'Orders list is empty',
			));
		}
    }
    public function create($oder)
    {
		
    }
    public function update($order_id,$order)
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
		$checkOrder = $userMedicineOrderTable->changeAutoRenewal($order_id,$order);
		$getorders	=$userMedicineOrderTable->getOrders($order_id,$order)->toArray();
		$getUserId=$userMedicineOrderTable->getUserId($order_id)->toArray();
		if(count($getUserId)!=0){
			$sendNotification = $notificationTable->sendRenewalOrderNot($order_id,$getorders[0],'1',$order['adminId'],'2',$getUserId[0]['user_id']);
		}
		return new JsonModel(array(
			'status'		=>	'success',
			'value'			=>	1,
		));
	}
		
    public function delete($id)
    {
       
    }
}